<template>
	<view class="">
		<!-- 背景图 -->
		<view class="">
			<!-- 医生卡片 -->
			<view class="p-10 bg1 justify-center flexflex hosCard" style="">
				<view class="mr10 bg-white" style="width: 160rpx; height: 160rpx; border-radius: 50%">
					<image
						:src="message.staffpic || 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw%2F2ee4072e-3b42-4a35-9931-50dba155d278%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1703217028&t=9cfda38ab54c3fcd92ce4f20120a5a2b'"
						style="border-radius: 50%;height: 160rpx;" class="wid80"></image>
				</view>
				<view class="f1" style="color: white">
					<!--  -->
					<view>
						<text class="f16 mr10">{{ message.uname || "李医生" }}</text>
						<text class="f13 mr10">{{ message.titleName || "大夫" }}</text>
						<text class="f13">{{ message.udepartmentname || "测试科" }}</text>
					</view>
					<!--  -->
					<view class="fa f12 mt5" v-if="message.ucompname != null && message.ucompname != ''">
						<image src="/static/img/position.png"  class=" mr5 size_10">
						</image>
						<view class="">
							{{ message.ucompname }}
						</view>
					</view>
					<view class="fa f12 mt5" v-if="message.uaddress != null && message.uaddress != ''">
						<image src="/static/img/road.png"  class="size_10 mr5"></image>
						<view class="">
							{{ message.uaddress || message.udetailedAddress }}
						</view>
					</view>
					<view class="fa f12 mt5" v-if="message.umobile != null && message.umobile != ''">
						<image src="/static/img/tel.png" class="size_10 mr5"></image>
						<view class="">
							{{ message.umobile }}
						</view>
					</view>
				</view>
				<view class="bg1"> </view>
				<view class="bg2"> </view>
			</view>

			<!-- 待处理 -->
			<view class="p-10" style="background-color: rgb(74, 165, 253); height: 310rpx">
				<!-- -->
				<view class="fa">
					<view class="fa f1 f15">
						<image src="/static/img/room.png"  class=" mr5 size_20"></image>
						<view style="color: white"> 我的诊室 </view>
					</view>
					<view @click="$pub.go('/pages/reView/reView')" class="waitdeal">
						<view class="flex-cen">
							<view class=""> 待处理事项： </view>
							<view class="box">
								<u-badge :value="count.cf || '无'" type="error"> </u-badge>
							</view>
						</view>
					</view>
				</view>
				<u-gap></u-gap>
				<!--  -->
				<view class="flexflex" style="min-height: 200rpx">
					<view class="f14 mr-10" @click="$pub.go('/pages/jiezhen/jiezhen')" style="
              background-color: white;
              width: 280rpx;
              padding: 20rpx;
              border-radius: 10rpx;
            ">
						<view class="flex">
							<view class="f1">
								<text class="c2d mr10">待接诊</text>
								<text class="cff">{{ count.djz || 0 }}</text>
							</view>
							<image src="/static/img/right.png" mode="widthFix" class="wid6"></image>
						</view>
						<view class="mt10">
							<image :src="val.avatar || '/static/img/user.png'"  class="size_40 mr5"
								v-for="(val, i) in from2" :key="i">
							</image>
						</view>
					</view>
					<view class="f14" @click="$pub.go('/pages/huifu/huifu')" style="
							  background-color: white;
							  width: 320rpx;
							  padding: 20rpx;
							  border-radius: 10rpx;
							">
						<view class="fa">
							<view class="f1">
								<text class="c2d mr10">接诊中</text>
								<text class="cff">{{ count.jzz || 0 }}</text>
							</view>
							<image src="/static/img/right.png" mode="widthFix" class="wid6"></image>
						</view>
						<view class="mt10">
							<image :src="val.avatar || '/static/img/user.png'"  class="size_40 mr5"
								v-for="(val, i) in from" :key="i"></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!--  -->
		<view v-if="false" class="fa tags" >
			<view class="" @click="$pub.go('/pages/fangzi/fangzi')">
				<image src="/static/img/bill.png" mode="widthFix" class="wid31"></image>
				<view class=""> 开药方子 </view>
			</view>
			<view class="">
				<image @click="$pub.go('/pages/manbing/manbing')" src="/static/img/two.png" mode="widthFix"
					class="wid38"></image>
				<view class=""> 慢病处理 </view>
			</view>
			<view class="">
				<image @click="$pub.go('/pages/yaoqing/yaoqing')" src="/static/img/one.png" mode="widthFix"
					class="wid43">
				</image>
				<view class=""> 邀请患者 </view>
			</view>
		</view>

		<!-- banner -->
		<view class="p-10">
			<image src="/static/img/banner.png" mode="widthFix" style="width: 100%"></image>
		</view>

		<!-- 新闻 -->
		<view class="news margin">
			<!--  -->
			<view class="newsWrap">
				<view class="left-line ml10 mr10"></view>
				<h4 class="size_16" style="margin-right: 480rpx">资讯</h4>
				<view class="flexflex" @click="$pub.go('/pages/index/articleList/articleList')">
					更多
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<!-- 列表 -->
			<view class="item ml10" v-for="(val, index) in consult" :key="index" @click="goPage(val)">
				<view class="title size_16 summary" style="height: 30rpx">
					{{ val.title }}
				</view>
				<view class="content size_14 text-ellipsis">
					{{ val.content }}
				</view>
				<view class="time size_12" style="padding: 12rpx 0 30rpx 0">
					{{ val.createTime || "2023-11-03" }}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		checkOpenGPSServiceByAndroid
	} from "@/utils/device.js";
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				/* 认证信息 */
				authStatus: 0,
				/* 定位 */
				mapData: {
					type: "2",
					userId: uni.getStorageSync("userInfo").userid,
					x: 0,
					y: 0,
				},
				/* 医生信息 */
				message: "",
				/* */
				from: [],
				from2: [],
				/* */
				count: {
					//待接诊数量
					djz: 0,
					//接诊中数量
					jzz: 0,
					//我的诊室，待审核处方数量
					cf: 0,
				},
				/*资讯 */
				consult: [],
				/*  */
				compid: uni.getStorageSync("compid"),
			};
		},
		onLoad() {
			/*  */
			this.authShow();
			
		},
		onShow() {
			this.getGps();
			/* 问政 */
			this.getList();

			/* 资讯  */
			this.getZixun();

			/* 问诊患者数量 */
			this.chatList();
			
			
			setTimeout(()=>{
				console.log(uni.getStorageSync("userInfo"), "uni.getStorageSync()");
				let ddd = uni.getStorageSync("userInfo")
				console.log(ddd, "ddd");
				if (ddd) {
					this.message = uni.getStorageSync("userInfo").userInfo;
				}
				console.log(this.message, 'this.message ');
			},1000)
			
		},
		methods: {
			goPage(val){
				this.$pub.go(
				  `/pages/articleDetail/articleDetail?data=${encodeURIComponent(
				    JSON.stringify(val)
				  )}`
				)
			},
			
			
			/* 获取待接诊患者数量 获取接诊中患者数量 */
			async chatList() {
				// 获取待接诊患者数量
				let djz = await this.$API.messageApi.listByDoctor(0);
				// 获取接诊中患者数量
				let jzz = await this.$API.messageApi.listByDoctor(1);
				if (djz) {
					//待接诊数量
					this.count.djz = djz.length;
					this.from2 = djz.slice(0, 3);
				}
				if (jzz) {
					//接诊中数量
					this.count.jzz = jzz.length;
					this.from = jzz.slice(0, 3);
				}
			},
			//我的诊室，待审核处方数量
			async getList() {
				let data = {
					x: uni.getStorageSync("map").x,
					y: uni.getStorageSync("map").y,
					pageNum: 1,
					pageSize: 5,
				};
				let re = await this.$API.abbreviationforApi.getList(data);
				console.log(re, "re");
				if (re.list.length != 0) {
					this.count.cf = re.list.length;
				} else {
					this.count.cf = "无";
				}
			},
			/* async*/
			authShow() {
				let auth = uni.getStorageSync("authStatus");
				console.log(auth, "auth 认证？、");
				/* 审核状态:0待审核;1审核通过;2审核失败 */
				// To do 审核
				if (auth == "0" || auth == null) {
					console.log("未认证页面");
					uni.reLaunch({
						url: "/pages/auth/auth",
					});
				} else if (auth == "1") {
					console.log("认证页面");
				} else {
					console.log("即不是已认证也不是为认证");
				}
			},
			async getMap() {
				let that = this;
				let re = await this.$API.mapApi.coordinate(this.mapData);
			},
			getGps(e) {
				let that = this;
				uni.getLocation({
					type: "wgs84",
					/* high */
					accuracy: "best",
					// isHighAccuracy: true,
					// highAccuracyExpireTime: 3000,
					success: function(res) {
						let map = {
							x: res.longitude,
							y: res.latitude,
						};
						that.mapData.x = res.longitude;
						that.mapData.y = res.latitude;
						uni.setStorageSync("map", map);
						console.log("gpsSucess");
						that.getMap();
					},
					fail: function(err) {
						console.log("gpsFalse");
						// #ifdef APP
						checkOpenGPSServiceByAndroid();
						// #endif
					},
				});
			},
			/* 资讯 */
			async getZixun() {
				console.log("infro");
				this.request({
					url: "/information/list",
				}).then((res) => {
					// console.log(res, "resINFRO");
					if (res) {
						this.consult = res.data.list;
					}
				});
			},
		},
	};
</script>




<style lang="scss" scoped>
	
	.hosCard{
		background-color: rgb(74, 165, 253);
		height: 300rpx;
		align-items: center;
	}
	
	.tags{
		padding: 60rpx;
		background-color: white;
		display: flex;
		justify-content: space-between;
		text-align: center;
		border-radius: 20rpx;
		margin-top: -20rpx;
	}
	
	.newsWrap{
		display: flex;
		justify-items: center;
		align-items: center;
		padding-top: 30rpx;
	}
	
	.waitdeal{
		background-color: white;
		color: #ffb444;
		border-radius: 50rpx;
		padding: 18rpx 30rpx;
	}
	
	.size_10{
		width: 20rpx;
		height: 20rpx
	}
	

	
	.size_20{
		width: 40rpx;
		height: 40rpx
	}	
	
	.size_40{
		width: 80rpx;
		height: 80rpx
	}	
		
	/* 指示器 */

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #ffffff;
			font-size: 12px;
		}
	}
</style>